<div>
    <a class="btn success" href="?page=new">New page</a>
    <?php foreach ($pages as $p): ?>
        <?php if ($p == $page)
            continue; ?>
        <a class="btn" href="?page=<?php echo $p; ?>"><?php echo $p; ?></a>
    <?php endforeach; ?>
</div>
<br />

<?php
$content = ORM::factory('page')
        ->where('page', '=', $page)
        ->limit(1)
        ->find();
?>

<form method="post">
    <fieldset>
        <legend><?php echo $page; ?></legend>
        <?php if (!$new) echo Form::hidden('page', $page); ?>

        <div class="row form-stacked" style="padding-left: 30px;">
            <div class="span2">&nbsp;</div>
            <div class="span4">
                <?php if ($new)://CPanel::input('Page', 'page'); ?>
                <div class="clearfix">
                    <label>Page</label>
                    <div class="input">
                        <input type="text" name="page" required />
                    </div>
                </div>
                <?php endif; ?>
            </div>
            <div class="span4">
                <div class="clearfix">
                    <label>Template</label>
                    <div class="input">
                        <input type="text" name="template" value="<?php echo ($new ? 'template' : $content->template); ?>" required />
                    </div>
                </div>
            </div>
        </div>
        <br />
        
        <ul class="tabs" data-tabs="tabs" style="padding-left: 150px;">
            <?php $active = ' class="active"'; ?>
            <?php foreach ($languages as $lang => $desc): ?>
                <li<?php echo $active; ?>><a href="#tab-<?php echo $lang; ?>"><?php echo $lang; ?> content</a></li>
                <?php $active = ''; ?>
            <?php endforeach; ?>
        </ul>

        <div class="pill-content">
            <?php $active = ' class="active"'; ?>
            <?php foreach ($languages as $lang => $desc): ?>
                <?php
                $content = ORM::factory('page')
                        ->where('lang', '=', $lang)
                        ->where('page', '=', $page)
                        ->find();
                ?>
                <div id="tab-<?php echo $lang; ?>"<?php echo $active; ?>>
                    <div class="clearfix">
                        <label>Title [<?php echo $lang; ?>]</label>
                        <div class="input">
                            <?php echo Form::input('title_' . $lang, $content->title); ?>
                        </div>
                    </div>
                    <div class="clearfix">
                        <label>Content [<?php echo $lang; ?>]</label>
                        <div class="input">
                            <?php
                            echo Form::textarea('content_' . $lang, $content->content, array(
                                'class' => 'span11',
                                'style' => 'height: 360px;'
                            ));
                            ?>
                        </div>
                    </div>
                </div>
                <?php $active = ''; ?>
            <?php endforeach; ?>
        </div>

        <div class="actions">
            <button class="btn primary" name="save_page" value="true">Save</button>
        <?php if (!$new): ?>
            <button class="btn error" name="remove_page" value="true">Remove</button>
        <?php endif; ?>
        </div>
    </fieldset>
</form>